package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.product.CategoryBrandVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/categoryBrand")
@Tag(name = "分类品牌管理模块")
public class CategoryBrandController {
    @Resource
    CategoryBrandService categoryBrandService;
    @Operation(summary = "根据3级分类id查询品牌列表")
    @GetMapping("/getAllBrandByC3id/{c3id}")
    public Result getAllBrandByC3id(@PathVariable("c3id")Long c3id){
        List<Brand> brandList = categoryBrandService.getAllBrandByC3id(c3id);
        return Result.ok().data(brandList);
    }
    @Operation(summary = "删除分类品牌")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        categoryBrandService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "新增分类品牌")
    @PostMapping("save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.ok();
    }
    @Operation(summary = "查询指定分类品牌")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        CategoryBrand categoryBrand = categoryBrandService.getById(id);
        return Result.ok().data(categoryBrand);
    }
    @Operation(summary = "更新分类品牌")
    @PutMapping("updateById")
    public Result updateById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateById(categoryBrand);
        return Result.ok();
    }
    @Operation(summary = "条件查询分类品牌分页数据")
    @GetMapping("page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize,
                       CategoryBrand categoryBrand){
        PageInfo<CategoryBrandVo> pageInfo = categoryBrandService
                .page(pageNum,pageSize , categoryBrand);
        return Result.ok().data(pageInfo);
    }

}
